<?php
require_model('base.class');
class doctorRole extends base {
    private $table = 'DoctorRole';
    private $primary = 'DoctorRoleId';
    function __construct() {
        parent::__construct($this->table,$this->primary);
    }
    function ApplyNewRole($params) {
        return $this->insert_item($params);
    }
    function DeleteRole($username, $roleId) {
        return $this->update_item(array('IsActive'=>0), array('UserName'=>$username, 'RoleId'=>$roleId));
    }
    function ApproveRole($username, $roleId) {
        return $this->update_item(array('IsActive'=>1, 'IsApproved'=>1), array('UserName'=>$username, 'RoleId'=>$roleId));
    }
    function GetApprovedRoleByDoctorUserName($username) {
        $time = date('Y-m-d');
        $res = $this->db->create_mapper($this->table)
            ->where(array('IsApproved'=>1,'IsActive'=>1, 'UserName'=>$username))
            ->where_col('BeginDate', $time, '<=' )
            ->where_col('EndDate', $time , '>=')
            ->find_all_by();
        return $res ? $res :array();
    }
    function GetUnApprovedRoleByDoctorUserName($username) {
        return $this->get_items(array('IsApproved'=>0, 'UserName'=>$username));
    }
}